// modules/goods/goods.controller.ts

import { Provide, Inject } from '@midwayjs/core';
import { CoolController, BaseController, BaseService } from '@cool-midway/core';
import { InjectEntityModel } from '@midwayjs/typeorm';
import { Column, Entity, PrimaryGeneratedColumn, CreateDateColumn, Repository } from 'typeorm';

/**
 * 商品表
 */
@Entity('goods')
export class GoodsEntity {
  @PrimaryGeneratedColumn()
  id: number;

  @Column({ type: 'int', comment: '分类ID' })
  categoryId: number;

  @Column({ type: 'varchar', length: 128, comment: '标题' })
  title: string;

  @Column({ type: 'varchar', length: 255, nullable: true, comment: '主图URL' })
  image: string;

  @Column({ type: 'numeric', precision: 12, scale: 2, default: 0, comment: '价格' })
  price: number;

  @Column({ type: 'text', nullable: true, comment: '详情' })
  description: string;

  @CreateDateColumn({ type: 'timestamp', comment: '创建时间' })
  createTime: Date;

  // 新增：所属分站ID
  @Column({ type: 'int', comment: '所属分站ID' })
  siteId: number;  // 分站ID
}

/**
 * 商品 控制器
 */
@Provide()
@CoolController({
  api: ['add', 'delete', 'update', 'info', 'list', 'page'],
  entity: GoodsEntity,
})
export class GoodsController extends BaseController {

  // 可添加自定义接口
  // @Post('/custom')
  // async custom(@Body() body) {
  //   return this.ok(await this.goodsService.doSomething(body));
  // }
}
